<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <title>欢乐中国活动报名微信支付</title>
    <style>
        html,body{
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #f4f4f4;
        }
        .message {
            width: 90%;
            height: 150px;
            background-color: #ffffff;
            border-radius: 5px;
            box-shadow: 0 0 10px #dddddd;
        }
        .message .content {
            width: 100%;
            height: 100px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.2rem;
            color: #333333;
            font-weight: bold;
        }
        .buttons {
            width: 100%;
            height: 50px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .button {
            flex: 1;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1rem;
            color: #333333;
            border-top: 1px solid #f4f4f4;
        }
        .button:first-child {
            color: #333333;
            border-bottom-left-radius: 5px;
        }
        .button:last-child {
            color: #ff4700;
            border-left: 1px solid #f4f4f4;
            border-bottom-right-radius: 5px;
        }
        .button:active {
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
<div class="message">
    <div class="content">请确认微信支付是否已完成</div>
    <div class="buttons">
        <div class="button" id="payFail">支付遇到问题</div>
        <div class="button" id="payComplete">已支付完成</div>
    </div>
</div>
<script src="//cdn.bootcss.com/jquery/3.3.0/jquery.min.js"></script>
<script>
  $(function(){
    checkPayResult()
    $('#payFail').click(function () {
      $.ajax({
        url: '/activity-api/activity.h5.check.wechat.pay?order_no={$orderNo}',
        headers: {
          'client-type': 'h5'
        },
        type: "get"
      }).done(function(e) {
        window.location.replace('http://h5.enjoychina.cc/order/detail/{$orderNo}')
      }).fail(function() {
        window.location.replace('http://h5.enjoychina.cc/order/detail/{$orderNo}')
      })
    })
    $('#payComplete').click(function () {
      window.location.replace('http://h5.enjoychina.cc/order/detail/{$orderNo}')
    })
  })
  // ajax轮询检测是否支付成功
  function checkPayResult () {
    $.ajax({
      url: '/activity-api/activity.h5.check.wechat.pay?order_no={$orderNo}',
      headers: {
        'client-type': 'h5'
      },
      type: "get"
    }).done(function(e) {
      console.log(e)
      if (e.code === 10000) {
        window.location.replace('http://h5.enjoychina.cc/order/detail/{$orderNo}')
      } else {
        setTimeout(function() {
          checkPayResult()
        },1000)
      }
    })
  }
</script>
</body>
</html>